package hu.jonas.time.client.model;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.smartgwt.client.widgets.grid.ListGridRecord;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Project implements Serializable {

	private static final long serialVersionUID = 3773960963674056628L;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String encodedKey;
	
	@Persistent
	@Extension(vendorName = "datanucleus", key = "gae.pk-id", value = "true")
	private Long keyId;
	
	@Persistent
	private String name;
	
	@Persistent
	private Set<Task> tasks;
	
	@Persistent
	private Set<Project> subProjects;
	
	@Persistent
	private Date dueDate;
	
	public Project() {
	}

	public String getEncodedKey() {
		return encodedKey;
	}
	
	public long getKeyId() {
		return keyId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Set<Task> getTasks() {
		return tasks;
	}

	public void setTasks(Set<Task> tasks) {
		this.tasks = tasks;
	}

	public Set<Project> getSubProjects() {
		return subProjects;
	}

	public void setSubProjects(Set<Project> subProjects) {
		this.subProjects = subProjects;
	}

	public Date getDueDate() {
		return dueDate;
	}

	public void setDueDate(Date dueDate) {
		this.dueDate = dueDate;
	}
	
	public ListGridRecord toRecord() {
		ListGridRecord record = new ListGridRecord();
		record.setAttribute("name", name);
		record.setAttribute("dueDate", dueDate);
		
		return record;
	}
	
	@Override
	public String toString() {
		StringBuilder result = new StringBuilder("Project [");
		result.append("id = ").append(keyId);
		result.append(", name = ").append(name);
		result.append(", dueDate = ").append(dueDate).append(" ]");
		
		return result.toString();
	}
}
